package com.mqtt.cn

import android.content.Intent
import android.os.Bundle
import com.google.android.material.snackbar.Snackbar
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.Toast
import com.mqtt.cn.databinding.ActivityMainBinding
import org.eclipse.paho.client.mqttv3.internal.wire.MqttAck

class MainActivity : AppCompatActivity() {

    private lateinit var appBarConfiguration: AppBarConfiguration
    private lateinit var binding: ActivityMainBinding

    val mMqttUtils by lazy { Mqtt() }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        mMqttUtils.Mqtt_init(this)
        mMqttUtils.startReconnect()
        binding.deviceDesc.text = "当前设备的UUID "+mMqttUtils.UUID
    }

    fun sendMsg(view: View) {
        mMqttUtils.publishmessageplus(mMqttUtils.mqtt_sub_topic, binding.edText.text.toString())
        Toast.makeText(this, "发送", Toast.LENGTH_SHORT).show()
    }

    private class MyWebViewClient : WebViewClient() {
        override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
            view.loadUrl(url)
            return false
        }
    }


}